﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ExportToPLMX.TxObjectNode
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;


namespace DnProcessSimulateCommands.ExportToPLMX;

[DataContract]
public class TxObjectNode
{
  [DataMember(Order = 0)]
  public string title;
  [DataMember(Order = 1)]
  public string psId;
  [DataMember(Order = 2)]
  public int units = 2;
  [DataMember(Order = 3)]
  public double[] bboxMin;
  [DataMember(Order = 4)]
  public double[] bboxMax;
  [DataMember(Order = 5)]
  public double[] xform;
  [DataMember(Order = 6)]
  public List<TxObjectNode> children;

  public TxObjectNode()
  {
    this.children = new List<TxObjectNode>();
    this.bboxMin = new double[3];
    this.bboxMax = new double[3];
    this.xform = new double[12];
  }

  public TxObjectNode(string name, string id)
    : this()
  {
    this.title = name;
    this.psId = id;
  }

  public void ToJSON(string filePath)
  {
    try
    {
      byte[] array;
      using (MemoryStream memoryStream = new MemoryStream())
      {
        new DataContractJsonSerializer(this.GetType()).WriteObject((Stream) memoryStream, (object) this);
        array = memoryStream.ToArray();
      }
      using (StreamWriter streamWriter = new StreamWriter(filePath, false))
        streamWriter.Write(Encoding.UTF8.GetString(array, 0, array.Length));
    }
    catch (Exception ex)
    {
      string message = ex.Message;
    }
  }

  public override bool Equals(object other)
  {
    TxObjectNode txObjectNode = other as TxObjectNode;
    bool flag = this.title.Equals(txObjectNode.title) && this.psId.Equals(txObjectNode.psId) && this.units.Equals(txObjectNode.units) && this.AlmostEquals(this.bboxMax, txObjectNode.bboxMax) && this.AlmostEquals(this.bboxMin, txObjectNode.bboxMin) && this.AlmostEquals(this.xform, txObjectNode.xform) && this.children.Count.Equals(txObjectNode.children.Count);
    foreach (TxObjectNode child1 in this.children)
    {
      TxObjectNode child = child1;
      flag = flag && child.Equals((object) txObjectNode.children.Find((Predicate<TxObjectNode>) (x => x.psId == child.psId)));
    }
    return flag;
  }

  private bool AlmostEquals(double[] thisArray, double[] otherArray)
  {
    bool flag = true;
    List<double> list1 = ((IEnumerable<double>) thisArray).ToList<double>();
    List<double> list2 = ((IEnumerable<double>) otherArray).ToList<double>();
    for (int index = 0; index < list1.Count & flag; ++index)
      flag = TxDoubleExtension.AlmostEquals(list1[index], list2[index]);
    return flag;
  }
}
